package com.lds.employment.service.impl;

import java.util.Date;
import java.util.List;

import com.lds.employment.domain.EmploymentStudentAssistance;
import com.lds.employment.domain.dto.TransferDto;
import com.lds.employment.mapper.EmploymentStudentAssistanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lds.employment.mapper.EmploymentAssistanceTransferMapper;
import com.lds.employment.domain.EmploymentAssistanceTransfer;
import com.lds.employment.service.IEmploymentAssistanceTransferService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 移交Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-05
 */
@Service
public class EmploymentAssistanceTransferServiceImpl implements IEmploymentAssistanceTransferService 
{
    @Autowired
    private EmploymentAssistanceTransferMapper employmentAssistanceTransferMapper;
    @Autowired
    private EmploymentStudentAssistanceMapper studentAssistanceMapper;

    /**
     * 查询移交
     * 
     * @param id 移交主键
     * @return 移交
     */
    @Override
    public EmploymentAssistanceTransfer selectEmploymentAssistanceTransferById(Long id)
    {
        return employmentAssistanceTransferMapper.selectEmploymentAssistanceTransferById(id);
    }

    /**
     * 查询移交列表
     * 
     * @param employmentAssistanceTransfer 移交
     * @return 移交
     */
    @Override
    public List<EmploymentAssistanceTransfer> selectEmploymentAssistanceTransferList(EmploymentAssistanceTransfer employmentAssistanceTransfer)
    {
        return employmentAssistanceTransferMapper.selectEmploymentAssistanceTransferList(employmentAssistanceTransfer);
    }

    /**
     * 新增移交
     * 
     * @param transferDto 移交
     * @return 结果
     */
    @Override
    @Transactional
    public int insertEmploymentAssistanceTransfer(TransferDto transferDto)
    {
        Long studentAssistanceId = transferDto.getStudentAssistanceId();
        EmploymentStudentAssistance StudentAssistance = studentAssistanceMapper.selectEmploymentStudentAssistanceById(studentAssistanceId);
        EmploymentAssistanceTransfer employmentAssistanceTransfer = new EmploymentAssistanceTransfer();

        //添加帮扶任务表
        employmentAssistanceTransfer.setTeacherId(StudentAssistance.getTeacherId());
        employmentAssistanceTransfer.setReceiveId(transferDto.getReceiveId());
        employmentAssistanceTransfer.setTransferTime(new Date());
        employmentAssistanceTransfer.setTransferNotes(transferDto.getTransferNotes());
        employmentAssistanceTransfer.setAssistanceTasks("帮扶任务移交，学生:"+StudentAssistance.getRealName());

        //修改学生帮扶表
        StudentAssistance.setTeacherId(transferDto.getReceiveId());
        StudentAssistance.setState("3");
        studentAssistanceMapper.updateEmploymentStudentAssistance(StudentAssistance);

        return employmentAssistanceTransferMapper.insertEmploymentAssistanceTransfer(employmentAssistanceTransfer);
    }

    /**
     * 修改移交
     * 
     * @param employmentAssistanceTransfer 移交
     * @return 结果
     */
    @Override
    public int updateEmploymentAssistanceTransfer(EmploymentAssistanceTransfer employmentAssistanceTransfer)
    {
        return employmentAssistanceTransferMapper.updateEmploymentAssistanceTransfer(employmentAssistanceTransfer);
    }

    /**
     * 批量删除移交
     * 
     * @param ids 需要删除的移交主键
     * @return 结果
     */
    @Override
    public int deleteEmploymentAssistanceTransferByIds(Long[] ids)
    {
        return employmentAssistanceTransferMapper.deleteEmploymentAssistanceTransferByIds(ids);
    }

    /**
     * 删除移交信息
     * 
     * @param id 移交主键
     * @return 结果
     */
    @Override
    public int deleteEmploymentAssistanceTransferById(Long id)
    {
        return employmentAssistanceTransferMapper.deleteEmploymentAssistanceTransferById(id);
    }
}
